import { createStore } from 'vuex'
import _ from "lodash";

export default createStore({
  state: {
    axiosCancels: [], // 所有需要取消请求的cancel数组
    ctxFormData: {},
    progressCfg: {},//文件上传进度
    uploadUrlCfg: {},//文件上传成功后
  },
  getters: {
  },
  mutations: {
    PUSH_AXIOS_CANCELS(state, cancel) {
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore
      state.axiosCancels.push(cancel);
    },
    SET_AXIOS_CANCELS(state, arr) {
      state.axiosCancels = arr
    },
    SYNC_CTX_FORM_DATA(state, data) {
      _.assign(state.ctxFormData, data)
    },
    CLEAR_CTX_FORM_DATA(state) {
      state.ctxFormData = {}
    },
    CHANGE_CTX_FORM_DATA(state, data) {
      let {key, value} = data
      // @ts-ignore
      state['ctxFormData'][key] = value
    },
    SET_PROCESS(state, data) {
      let {name, progress} = data
      // @ts-ignore
      state.progressCfg[name] = progress
    },
    SET_UPLOAD_URL(state, data) {
      let {name, url} = data
      // @ts-ignore
      state.uploadUrlCfg[name] = url
    }
  },
  actions: {
  },
  modules: {
  }
})
